package com.kgc.basicprovider.controller;

import com.kgc.basic.pojo.Account;
import com.kgc.basic.remote.AccountRemote;
import com.kgc.basic.util.ResponseMsg;
import com.kgc.basicprovider.service.AccountService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
public class AccountController implements AccountRemote {
    private Logger logger = LoggerFactory.getLogger(AccountController.class);

    @Autowired
    private AccountService accountService;


    @Override
    public ResponseMsg selectAccountByPage(@RequestBody Map<String, Object> map) {
        logger.info("AccountController selectAccountByPage params{}", map);
        ResponseMsg responseMsg = accountService.selectAccountByPage(map);
        logger.info("AccountController selectAccountByPage responseMsg{}", responseMsg);
        return responseMsg;
    }

    @Override
    public ResponseMsg insertAccount(@RequestBody Account account) {
        logger.info("AccountController insertAccount params{}", account);
        ResponseMsg responseMsg = accountService.insertAccount(account);
        logger.info("AccountController insertAccount responseMsg{}", responseMsg);
        return responseMsg;
    }

    @Override
    public ResponseMsg updateAccount(@RequestBody Account account) {
        logger.info("AccountController updateAccount params{}", account);
        ResponseMsg responseMsg = accountService.updateAccount(account);
        logger.info("AccountController updateAccount responseMsg{}", responseMsg);
        return responseMsg;
    }

    @Override
    public ResponseMsg deleteAccount(@RequestParam("id") int id) {
        logger.info("AccountController deleteAccount params{}", id);
        ResponseMsg responseMsg = accountService.deleteAccount(id);
        logger.info("AccountController deleteAccount responseMsg{}", responseMsg);
        return responseMsg;
    }

    @Override
    public ResponseMsg selectAccountByCode(String code) {
        logger.info("provider AccountController selectAccountByCode code:{}", code);
        ResponseMsg msg = accountService.selectAccountByCode(code);
        logger.debug("provider AccountController selectAccountByCode msg:{}", msg);
        return msg;
    }

    @Override
    public ResponseMsg selectAllAccount() {
        logger.info("AccountController selectAllAccount ");
        ResponseMsg responseMsg = accountService.selectAllAccount();
        return responseMsg;
    }

}
